package com.per.mybootall.aop.example2;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.per.mybootall.pojo.User;
import com.per.mybootall.pojo.UserPo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * 在有多个切面的情况下，order越小则越先进入哪一个切面
 *
 * */
@Aspect
@Component
@Order(1)
public class PermissionFirstAdvice {
    // 定义一个切面，括号内写入第1步中自定义注解的路径
    @Pointcut("@annotation(com.per.mybootall.aop.example2.PermissionAnnotation)")
    private void permissionCheck() {
    }

    @Around("permissionCheck()")
    public Object permissionCheckFirst(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("===================第二个切面===================：" + System.currentTimeMillis());

       MethodSignature methodSignature=(MethodSignature) joinPoint.getSignature();
      String[] st=  methodSignature.getParameterNames();
       String[] str= methodSignature.getParameterNames();

       for(String s:st){ System.out.println("name:"+st); }
       for(String ss:str){ System.out.println("par:"+ss); }
        //获取请求参数，详见接口类
        Object[] objects = joinPoint.getArgs();

       for(Object obj:objects){
           System.out.println(obj);
           if(obj instanceof UserPo){
               UserPo userpo = (UserPo) obj;
               System.out.println(userpo.getPassword()+";"+userpo.getUsername()+";"+userpo.getPhotomessahes()+";"+userpo.getUuid());
           }
       }
//        ObjectMapper objectMapper=new ObjectMapper();
//        UserPo U=  objectMapper.convertValue(objects, UserPo.class);
        return joinPoint.proceed();
    }
}
